﻿using Daemon.Model;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Daemon.Data.Infrastructure.Auth
{
    public class BaseAuthUser
    {
        public int Id { get; set; }

        public string UserName { get; set; }

        public string Password { get; set; }

        public string Avatar { get; set; }

        public bool IsAdmin { get; set; }

        public int? SchoolId { get; set; }

        public bool Deleted { get; set; }

        public DateTime AddTime { get; set; }

        public DateTime UpdateTime { get; set; }

        public bool Deactivated { get; set; }

        public string Email { get; set; }

        private List<int> _roleIds;

        public List<int> RoleIds
        {
            get
            {
                return _roleIds ?? (_roleIds = UserRoles?.Select(i => i.Id)?.ToList());
            }

            set
            {
                _roleIds = value;
            }
        }

        public List<UserRole> UserRoles { get; set; }

        public List<AdminRole> Role { get; set; }

        public string UserType { get; set; }
        public List<string> AuthCode { get; set; }

        public List<AdminRole> Roles { get; set; }

        public BaseAuthUser ToSimple()
        {
            return new BaseAuthUser
            {
                Id = Id,
                IsAdmin = IsAdmin,
                UserName = UserName,
                Avatar = Avatar,
                SchoolId = SchoolId,
                AuthCode = AuthCode,
                RoleIds = UserRoles?.Select(i => i.Id).ToList() ?? new List<int>(),
            };
        }
    }
}
